Introduction: Variable 0-12V, Digitally Controlled, Power Supply Using a Laptop Wall Wart & Ardunio

About: MS EE student at Stanford University
The goal of this Instructable is to make a functional, Ardunio digitally controlled, power supply. We tested the supply and controller so that you can grab your old laptop wall wart (output voltage between 14 and 20V), connect it to the supply's Vin line and digitally specify what output voltage you want in the range between 0 and 12 V. Assuming you already have an Ardunio and a laptop charger with the right specs, a single source should cost around $15 in parts. This Instructable will walk through building a single supply (with the option of building two) that is controlled by a single Ardunio Uno.


To build a single switching buck supply, as show in the circuit below, you will need the following parts (about $15):
1 x 22uF Cap - Link
2 x 1000uF Cap - Link
1 x 680uH Inductor - Link
1 x 10k Res - Link
2 x 100k Res - Link
1 x IRF9Z34N PMOS - Link
2 x 1N5818 Diode - Link
1 x LT1632 Opamp - Link

You have the option of building two supplies. You'll need to double the above order if you want to build two supplies.

Your supply will need to drive a load. We suggest first starting with resistors to ensure that the circuit is working properly. Please be aware of Ohms law and avoid using loads which are not rated for the wattage that will appear across them... unless you love the smell of magic smoke. Use good judgment.

You will additionally need the following:
1 x breadboard to assemble the circuits on - Link
1 x Ardunio Uno (will work with other Ardunio distributions, but code modification is up to you) - Link
1 x laptop charger / wall wart with a Vout between 14 and 20V (most chargers) at a minimum of 3A - Link
Lots of cabling (wires, alligator clips, etc as you need) to make the connections

You may also want:
Heat shrink & a heat shrink gun
Electrical tape
Multimeter (for testing)
Oscilliscope (for testing)

This Instructable was made as a class project for EE 122A at Stanford University under Professor Greg Kovacs. The team included Michael Digman and Christian Elder. 

Step 1: Laptop Adapter Selection and Modification

The first step on your journey is to pick a laptop power adapter. For our version, we used a Lenovo 65W adapter, which outputs DC 20 V. Although we used this adapter, any laptop adapter with < 20 V and > 40 Watts should suffice, and we’ve tested our power supply with input voltages down to 14 V with minimal effect on the supply output characteristics.

Now that we have a power adapter, we need to alter it for use with the breadboard. Although you can choose to use a female barrel plug adapter, we chose to remove the barrel plug. We should take the time now to note that this probably voids the adapter’s warranty, so if you’re thinking of ever returning the adapter, you probably should buy a barrel plug adapter.

Removing the barrel plug entailed cutting the cord below the plug, stripping the outermost plastic shielding, and grouping the ground wires, which surround the inner plastic shielding. After grouping the ground wires into a bundle, we strip the inner plastic shielding, making sure to avoid letting the ground wires contact the inner power wires. With the two bundles of wires separated, we soldered each bundle to a wire, red for the power (inner) wires and black for the ground (outer) wires. For additional safety, we used electrical tape to separate the two wires. Now we can build our power supply circuit.

Step 2: PWM Signal Amplifier

We begin our supply circuit build by building an amplifier to amplify the Arduino PWM signal from 0-5V to the rails provided by our laptop adapter using an LT1632 op amp.

  1. Short the rails, red to red (positive), blue to blue (ground) (see first image)
  2. Place the op amp across the middle of the breadboard.
  3. Connect pin 8 (V+) to the positive rail and pin 4 (V-) to ground
  4. Connect the 10 kOhm resistor from pin 2 to ground (Note: the image incorrectly connects the resistor to the positive rail. This is amended in later images)
  5. Connect the 100 kOhm resistor from pin 2 to pin 1 (see second image)

Step 3: Power Supply Circuit - Part 1/3

Now that we have adequately amplified the Arduino’s PWM signal, let’s add the switch the PWM is controlling, the IRF9Z34N PMOSFET. The pins on this component are, from left to right, Gate, Drain, and Source. We will connect:
  1. the gate pin to the output of the LT1632 (pin 1)
  2. the source pin to the positive rail
We will connect the drain in the next step.

Step 4: Power Supply Circuit - Step 2/3

With the switch in place, we add the passive and energy storing components: input and output capacitors, diodes, and an inductor.
Connect:
  1. one terminal of the inductor to the drain pin of the IRF9X34N
  2. cathode of 1N5818 diode to the same terminal of the inductor, anode to ground
  3. anode of a second 1N5818 diode to the other terminal of the inductor
  4. the two 1000 uF capacitors in parallel from the cathode of the second diode to ground
  5. the 22 uF capacitor from the positive rail to ground
The node connecting the anodes of the 1000 uF capacitors is the output of the power supply.

Step 5: Power Supply Circuit - Part 3/3

To sense the output voltage on the Arduino, we need to step the output voltage down to a range of 0-5V. We accomplish this by using a resistive divider with sufficiently large resistors to reduce current draw. Connect:
  1. one side of the 300 kOhm resistor to the output node, the other to a floating node
  2. one side of the 100 kOhm resistor to the floating node, the other to ground
The middle node will be fed back to the Arduino for control. We will now connect the Arduino to the power supply. We begin by shorting the PWM ground terminal to one of the ‘analog in’ ground terminals. See first image.

We then connect:
  1. the other ‘analog in’ ground terminal to the ground rail on the breadboard
  2. PWM pin 9 to pin 3 of the LT1632 op amp
  3. A1 to the middle node of the voltage divider
See second image.

We have now built a power supply circuit. Before connecting it to the laptop adapter, let’s look at the code controlling the supply.

Step 6: Arduino Code

Let’s get the Arduino up and running:
  1. Download and install the Arduino “language”
  2. Download and unzip the Arduino code, arduino_2src.zip (attached below)
  3. Open arduino_2src/arduino_2src.ino
  4. Adjust the variable 'inputVoltage' to the voltage rating of your laptop adapter (see first image)
  5. Connect Arduino Uno to computer via USB and record its serial port
    1. Select Tools > Serial Port > /dev/tty.usbmodemXXXX (see second image)
    2. Write down this serial port designation for the next step
  6. With the Arduino Uno plugged into the computer via USB, upload the code

The Arduino is now controlling the PWM signal, defaulting to the “Off” state, in which the output voltage of the power supply is 0. We will set the output voltage using a GUI which communicates with the Arduino over the serial port.

Step 7: GUI Code

Now for the GUI part:
  1. Download and install the Processing language
  2. Download and unzip the GUI code, processing_gui.zip (attached below)
  3. Open processing_gui/processing_gui.pde
    If we try to run the GUI code at this point, we see that we need to install the g4p_controls library.
    (SEE FIRST IMAGE)
  4. Install g4p_controls library
    1. Select Sketch > Import Library… > Add Library… (see second image)
    2. Search for ‘g4p_controls’
    3. Install ‘G4P’ (see third image)
  5. Set the variable ‘portName’ to the Arduino’s serial port, as captured in the previous step, as a string (see fourth image)
  6. With the Arduino plugged in, run GUI code (see fifth image)
  7. To adjust the power supply's voltage
    1. select the desired output voltage from the drop-down menu
    2. press 'On'
We now have the control loop for our power supply. Only one more step before we let you run loose with your new power supply!

Step 8: Connect Laptop Adapter

Well, now we have a fully functional control loop and a power supply circuit, but no input voltage!

Remember that laptop adapter we made you modify in the first step? Go ahead and connect it to the rails of the breadboard now.

Remember to attach a test load resistance between the output node and ground. As mentioned before, ensure that the resistor can handle the power drop you intend to put across it. Hook up your multimeter to the output of the supply and change the voltage of 'Source 1' in the GUI. The reading on the multimeter should adjust to the voltage you set.

You now have a working digitally-controlled 0-12V power supply!! Congrats!

Step 9: Building Dual Supplies

Should you want to build two supplies, you will use the same Ardunio and the same wall wart but you much build up another buck supply. Follow steps 2 through 8 again. The Ardunio needs to read in the feedback voltage from the new supply and must drive with a PWM generator that is separate from the first supply. This means you'll need to make a few simple modifications:

1) Both supplies must share the same Vin rails (V+ and ground)
2) PWM pin 10 to pin 3 of the LT1632 op amp
3) A2 to the middle node of the voltage divider

For comparison with the first source:
Source 1 must be driven by a PWM generator on pin 9 and must read in source 1's feedback voltage in A1
Source 2 must be driven by a PWM generator on pin 10 and must read in source 2's feedback voltage in A2

That's it! The picture shows two supplies built on separate breadboards, but two supplies can easily be built on a single breadboard. The Ardunio code and Processing GUI are already setup to handle two sources.

Step 10: Closing Notes

Basic Supply Characterization:
  • Each supply can source about 0.6A. We do not suggest going above this as the sag in the output voltage increases with smaller Rload.
  • There is at most a sag of 0.2V and this occurs in a two source configuration at driving 12V when both sources are connected to small Rloads.
  • The worst supply ripple observed is about 0.2V at with very low loads
  • For small Rout, the buck supply can reach an efficiency (Pout/Pin) of about 90% at around 12V. This efficiency does not include the power required to operate the Ardunio.
  • It is possible for the supply to output voltages up to approximately Vin-1, we leave doing this as an exercise.

Discharging Output Caps and Settling Time:
The load resistance and the output capacitors have an associated time constant. When switching from a high voltage to a low one (ex: from 12 to 1V), the output caps discharge the excess voltage through the load resistance. With very high load resistances (>10K), the output caps discharge much slower than with low load resistances (<1K). With an Rload at 20 Ohms, we've observed a settling time from 12 to 0V of about 260ms. With an Rload of 100K, we've observed a settling time from 12 to 0V of 3 minutes. Be very aware that when driving a high Rload, switching to a lower output voltage will take time. This can always be circumvented by placing a low resistance (<1K) in parallel with your Rload, again make sure that the low resistance is rated for the desired power dissipation.

Part Sizing:
The input capacitor, inductor and output cap were initially sized using this excellent documentation from TI.
http://www.ti.com/lit/an/slva477a/slva477a.pdf

The output capacitors were changed to be much larger than predicted because we wanted to cut down on the output ripple caused by the controller.

Design Fundamentals:
This video explains the very basics of a buck circuit in theory: http://www.youtube.com/watch?v=VCyYi9g_hI0

To learn more about Buck design check out this amazingly detailed document by TI: http://www.ti.com/lit/an/slva057/slva057.pdf

You may notice that our topology has an additional schottky diode between the inductor and the output capacitor, feedback network and load resistance. This diode was placed intentionally to aid in mitigating the effects of discontinuous mode for small output currents (large Rout). The proportional controller running on the Ardunio should be capable of working with the circuit without this diode in place, however we recommend that you leave it there.

Build My Lab Contest

Fourth Prize in the
Build My Lab Contest